home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia 1995 April / Informatica Multimedia CD - Epimundo.iso / DOS / FILEFIND / SNR.ZIP / SNR503.DOC < prev    next >
Encoding:
Text File  |  1993-05-30  |  66.0 KB  |  1,799 lines

  1.  
  2.  
  3.  
  4.      TITLE:         SNR.EXE   VERSION: 5.03
  5.  
  6.      PURPOSE:       Multi-string simultaneous Search 'N' Replace program
  7.  
  8.      RELEASE DATE:  5/31/93
  9.  
  10.      AUTHOR:        THOMAS A. LUNDIN
  11.                     16267 Hudson Avenue
  12.                     Lakeville, MN 55044
  13.                     day phone: (612) 588-7571
  14.                     nights/weekends: (612) 431-5805
  15.                     CompuServe ID [70523,262]
  16.  
  17.      REGISTRATION:  $50 per copy; volume and site licenses available.
  18.                     Registered version discards the opening shareware
  19.                     compliance screen, and a free multi-window DOS text
  20.                     editor is bundled with the package.
  21.  
  22.                     Registration guarantees technical support; unregistered
  23.                     users will receive support on a time-available basis.
  24.  
  25.                     Fill out and return the ORDER.FRM file along with your
  26.                     payment to register your copy.
  27.  
  28.      DESCRIPTION:   SNR is a multi-string search-and-replace filter. Both
  29.                     text and binary files can be processed by the program.
  30.                     SNR will translate a file of any size that your system
  31.                     can handle.
  32.  
  33.                     Version 5 of SNR brings many new advanced conversion
  34.                     capabilities to the program, such as:
  35.  
  36.                     - wild-card conversion patterns
  37.                     - variable-length conversion patterns
  38.                     - start-of-file and end-of-file conversions
  39.                     - text field padding
  40.                     - table chaining
  41.                     - enhanced context flags
  42.  
  43.                     Up to 2,500 multi-character (m:n) equations can be
  44.                     entered into an SNR table, each of which can be a
  45.                     maximum of 4,999 characters in length. Total conversion
  46.                     space is limited to 64,000 characters. All search-and-
  47.                     replace operations are performed in a single pass.
  48.                     Context flag conversion allows toggling between two
  49.                     different output strings for the same input string.
  50.                     Wild card patterns allow unspecific character strings
  51.                     to be matched and converted.
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                       -1-                     SNR+ VER 5.03
  64.  
  65.  
  66.  
  67.                                 REVISION HISTORY
  68.  
  69.           5.02 - 5/26/93
  70.           Major rewrite. Added advanced conversion features such as wild
  71.           card pattern matching, variable-length patterns, field padding,
  72.           and so on. Allow file names to contain DOS wild cards, also.
  73.           Allow multiple-table chaining on the command line. Allow output
  74.           file subdirectory specification. Greatly expanded program
  75.           capacities. Allow 16 context flags. Change default bit-masking
  76.           from 7-level to 8-level as this is the more harmless option.
  77.  
  78.           4.0 - 7/19/90
  79.           Removed OS/2 compatibility. Nobody used it. Allow 256 1:1
  80.           equations to be loaded in addition to 50 m:n equations. Added
  81.           context flag.
  82.  
  83.           3.01 - 11/3/89
  84.           Program recompiled for family mode, meaning it will run as-is
  85.           under DOS, OS/2 real mode, and OS/2 protected mode.
  86.  
  87.           Also improved I/O throughput on fast disk drives.
  88.  
  89.           3.0 - 9/27/89
  90.           The program has been completely rewritten. The pesky bugs that
  91.           were present in versions 1.5 and 2.0 have been eliminated.
  92.  
  93.           All binary characters INCLUDING NULLS can now be searched and
  94.           replaced. Nulls can also be entered as part of a larger search-
  95.           and-replace equation.
  96.  
  97.           An automatic "bit-stripping" feature has been added which removes
  98.           the high-order bits from input characters, forcing 8-bit codes
  99.           into 7-bit ASCII. The feature can be selectively disabled for
  100.           binary files.
  101.  
  102.           The equation length has been increased to 200 characters, which
  103.           can be split into search and replace sides of any length, as long
  104.           as the total does not exceed 200.
  105.  
  106.           Equations no longer need to be in any specific order.
  107.  
  108.           The average speed of the program has been vastly improved,
  109.           especially for multiple and high-occurrence search and replaces.
  110.  
  111.           The program no longer needs to read itself for runtime
  112.           parameters.
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.                                       -2-                     SNR+ VER 5.03
  127.  
  128.  
  129.  
  130.                                PROGRAM OPERATION
  131.  
  132.      The command line invocation is:
  133.  
  134.           snr [@]filename ext table[ table2...] [/d] [/opathname] [/r]
  135.  
  136.      1.   "filename" is the name of the DOS file you wish to convert. The
  137.           DOS wildcard characters "*" and "?" are allowed here, and they
  138.           will result in all files matching the name pattern to be
  139.           converted at one time. An at-sign (@) in front of the filename
  140.           indicates that the file contains a list of file names to convert.
  141.           There are two ways of creating the list of file names: the first
  142.           is to use the DOS DIR command and redirect its output to a file,
  143.           like this:
  144.  
  145.                dir *.txt >dirfile
  146.  
  147.           This will create a disk file named "dirfile" which contains a
  148.           directory list of all files with a ".TXT" extension. You can edit
  149.           this file if you want, to weed out certain files you don't want
  150.           and retain the others.
  151.  
  152.           You can also create a list file manually by just creating a file
  153.           with a text editor and typing in the path and file names for each
  154.           of the files you wish converted. Example:
  155.  
  156.                d:\data\test.txt
  157.                c:\bigfiles\tapedat.asc
  158.                c:\windows\win.ini
  159.  
  160.           The converted output files will appear in your current directory.
  161.           You can optionally direct the output to another directory with
  162.           the /o option, explained later.
  163.  
  164.      2.   "ext" is the filename extension you wish to assign each output
  165.           file. The output files are created by adding this extension onto
  166.           the name of the input file. If you are converting multiple input
  167.           files from a DIRLIST, or from a wild card in the command line,
  168.           all of the resulting output files will have the same extension.
  169.           The choice of an extension is important; if you accidentally
  170.           choose an extension which is already used by another file, you
  171.           will overwrite the existing file, losing its data in the process.
  172.           SNR will not warn you of impending overwrites. Use an extension
  173.           which you are sure is unique.
  174.  
  175.           Extensions can be the DOS device names CON, NUL, AUX, and PRN. In
  176.           any of these four cases, an output file is NOT created on disk;
  177.           rather, the output is redirected to the console (CON), nowhere
  178.           (NUL), the rs232 port (AUX), or the printer (PRN). Using CON is
  179.           handy for a quick preview of the conversion process before
  180.           storing it to disk, although if you preview binary files to CON,
  181.           be aware that hex code 1A (DOS end-of-file) will terminate the
  182.           conversion display, perhaps prematurely. (This permature
  183.           termination will NOT occur when you store to disk -- it is an
  184.           artifact of displaying to the console.) Also, some binary
  185.           characters will set the PC speaker beeping when you display to
  186.           the screen.
  187.  
  188.  
  189.                                       -3-                     SNR+ VER 5.03
  190.  
  191.  
  192.  
  193.  
  194.      3.   "tablename" is the file name and optional path which contains
  195.           your string translation "equations". Although no restrictions are
  196.           placed upon the tablename (aside from conforming to the DOS
  197.           naming format), for sake of clarity it is suggested that you
  198.           adopt a consistent naming scheme for them, (say, with an *.S
  199.           extension). Creating conversion equations is discussed in more
  200.           detail later. You may specify more than one table at a time on
  201.           the command line; the effect of this is that SNR will convert
  202.           your input files through each table in sequence. The contents of
  203.           the output files will be just as if you had run SNR a number of
  204.           times in a row.
  205.  
  206.      4.   "/d" is an option which replaces the original input file with the
  207.           converted data. The extension which you specify on the command
  208.           line is used as a temporary intermediate file until the
  209.           conversion is complete, at which time the program deletes the
  210.           original input file and renames the temporary output file to the
  211.           input name.
  212.  
  213.      5.   "/o" is an option which allows you to place the output files in
  214.           some directory other than the current directory. The /o is
  215.           followed immediately by the name of the directory path (no spaces
  216.           in between).
  217.  
  218.      6.   "/r" is an option used only in conjuction with the /o option; it
  219.           is meaningless by itself. /r forces all of the output files in
  220.           the other directory to retain the same name as the original input
  221.           files. At the end of the conversion run using this option, you
  222.           will have two directories of files with the same names, but the
  223.           data in the files in one of the directories will have been
  224.           converted.
  225.  
  226.      7.   The options /o, /r, and /d may appear in a list file, after the
  227.           name of the file to convert. Example:
  228.  
  229.                d:\data\file.1 /od:\
  230.                d:\data\file.2
  231.                c:\text\may.doc
  232.  
  233.           In the above example, all of the files in the list will be
  234.           converted and stored on the root directory of drive D:. These
  235.           option codes may NOT appear in a list file created by redirecting
  236.           the DOS DIR command to a file.
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.                                       -4-                     SNR+ VER 5.03
  253.  
  254.  
  255.  
  256.                              COMMAND LINE EXAMPLES
  257.  
  258.      C>snr tstfil.doc txt tst.s
  259.  
  260.           The above command line will convert input file "tstfil.doc"
  261.           through table "tst.s" and create output file "tstfil.txt".
  262.  
  263.      C>snr @dirlist p1 sample.s
  264.  
  265.           The above command line will convert a group of files listed in
  266.           the file "dirlist" through table "sample.s" and create a group of
  267.           output files with extensions of *.p1.
  268.  
  269.      C>snr *.c xxx pass1.s pass2.s pass3.s /d
  270.  
  271.           The above command line will convert a group of files matching the
  272.           DOS file name pattern "*.c" through the three tables "pass1.s",
  273.           "pass2.s" and "pass3.s" in order, and the converted output files
  274.           will replace the original input files. (The temporary
  275.           intermediate files will have an extension of *.xxx.)
  276.  
  277.      C>snr mytest.dat da2 pass1.s /od:\
  278.  
  279.           The above command will convert the input file "mytest.dat"
  280.           through table "pass1.s" and create an outfile named "mytest.da2"
  281.           in the root directory of drive D:.
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.                                       -5-                     SNR+ VER 5.03
  316.  
  317.  
  318.  
  319.                            CREATING CONVERSION TABLES
  320.  
  321.      SNR tables are ASCII text files which contain the search-and-replace
  322.      equations used by the program. Any word processor or text editing
  323.      program capable of loading and saving plain ASCII text files will be
  324.      sufficient to create conversion tables. (The registered version of SNR
  325.      is bundled with a free multi-window DOS text editor for this purpose.)
  326.  
  327.      Up to 2,500 of these equations can be entered in a single table, and
  328.      each equation can consist of up to 4,999 characters split freely
  329.      between the search side and the replacement side. Blank lines in a
  330.      table will be ignored. The maximum size of a table is limited to
  331.      64,000 characters. These equations will be matched against the input
  332.      file in a single pass, resulting in a converted output file.
  333.  
  334.      EQUATION TYPES
  335.      This manual may refer to certain equation types from time to time. The
  336.      equation types that are handled by SNR are as follows:
  337.  
  338.      1:0  an equation comprising one character on the left side and no
  339.           characters on the right side
  340.      1:1  an equation with one character on the left side and one character
  341.           on the right side
  342.      1:n  an equation with on character on the left side and two or more
  343.           characters on the right side
  344.      m:0  an equation with two or more characters on the left side, and no
  345.           characters on the right side
  346.      m:1  an equation with two or more characters on the left side, and one
  347.           character on the right side
  348.      m:n  an equation with two or more characters on the left side, and two
  349.           or more characters on the right side
  350.  
  351.      FORMAT OF EQUATIONS
  352.      The simplest form of conversion equation consists of literal search
  353.      and replace text separated by an equals sign. A sample 1:1 equation
  354.      would be:
  355.  
  356.           A=a
  357.  
  358.      The above equation would translate an upper-case 'A' to a lower-case
  359.      'a'.
  360.  
  361.      A sample m:n equation would be:
  362.  
  363.           Now is the time=NOW IS THE TIME
  364.  
  365.      The above equation will translate the words "Now is the time" to all
  366.      upper-case. Notice that spaces ARE SIGNIFICANT characters in an
  367.      equation, so don't use them carelessly if you don't mean to have them
  368.      converted.
  369.  
  370.      1:0 and m:0 equations ignore search strings (that is, throw it away on
  371.      output). They are defined simply by leaving out a replacement string,
  372.      like this:
  373.  
  374.           Now is the time=
  375.  
  376.  
  377.  
  378.                                       -6-                     SNR+ VER 5.03
  379.  
  380.  
  381.  
  382.      If you want to output word spaces at the end of a replacement string,
  383.      but your text editor strips trailing spaces, you can define them as
  384.      hex codes:
  385.  
  386.           Now is the time =NOW IS THE TIME\20
  387.  
  388.      In fact, any hex code can be formed from a backslash followed by two
  389.      hex digits (0-9, a-f, A-F). You'd normally use hex codes to search or
  390.      replace binary characters that can't be generated directly from the
  391.      keyboard. For instance, a carriage return/line feed sequence (CRLF)
  392.      can be specified like this:
  393.  
  394.           \0d\0a\0d\0a=\0d\0a
  395.  
  396.      The above equation will convert two CRLFs in a row to a single CRLF.
  397.  
  398.      SNR RESERVED CHARACTERS
  399.      There are three ASCII characters which MUST be specified as hex codes
  400.      in an SNR equation, since they have special meaning in their normal
  401.      ASCII form. They are:
  402.  
  403.      Backslash (\), which must be entered as \5c
  404.      Equals (=), which must be entered as \3d
  405.      Asterisk (*), which must be entered as \2a
  406.  
  407.      If you forget to follow this notation, you will very likely trigger
  408.      error messages when you attempt to run a conversion.
  409.  
  410.      EXTRA-LONG EQUATIONS
  411.      SNR can handle equation lengths up to 4,999 characters. It's quite
  412.      likely that you will never encounter this limit. Even so, your word
  413.      processor or text editor may have a much smaller limit on the number
  414.      of characters you can enter per line. Should you find you need to
  415.      carry an equation over from one line to the next, you can end a line
  416.      with \+ as the last item in the line, and SNR will automatically add
  417.      the next following line to the same equation. You can have as many
  418.      continuation lines as you need to. Example:
  419.  
  420.           Now is the time for all good men=NOW IS THE TIME    \+
  421.           \20FOR ALL GOOD MEN \ This is all one continued equation
  422.  
  423.      Be mindful that any spaces that occur before the \+ continuation code
  424.      are ignored (an exception to the all-spaces-are-significant rule). Any
  425.      text that appears on the same line after the \+ code is ignored.
  426.  
  427.      ENDING YOUR TABLES
  428.      The end of a table is signified by the end of your equations. You may
  429.      also place a \\E on a line by itself as an end-of-table marker. This
  430.      code is optional, but recommended, since it will prevent SNR from
  431.      inadvertently reading past the intended last line of your equations
  432.      (some word processors may pad their last blocks with garbage or with
  433.      an EOF character, which SNR would attempt to read as the start of a
  434.      new equation). A sure bet that you need to place the \\E code at the
  435.      end of your tables is if SNR occasionally aborts with the message:
  436.  
  437.           Incomplete equation (missing right half):
  438.  
  439.  
  440.  
  441.                                       -7-                     SNR+ VER 5.03
  442.  
  443.  
  444.  
  445.      ...and you are unable to see that any of your equations is incomplete.
  446.  
  447.      REPEATING CHARACTERS
  448.      SNR provides a shorthand notation for describing a large number of
  449.      repeating characters. Rather than entering an equation that looks like
  450.      this:
  451.  
  452.           AAAAAAAAAAAAAAAAAAAAAAAAA=bbbbbbbbbbbbbbbbbbbb
  453.  
  454.      ...you can describe it like this:
  455.  
  456.           *(25)A=*(20)b
  457.  
  458.      Any character can be repeated using this notation. By changing the
  459.      repeat value in parentheses, you accomplish the same thing as typing
  460.      the repeat character that number of times. NOTE: SNR will actually
  461.      expand a shorthand notation into longhand notation before it begins
  462.      conversion, so make sure you don't inadvertently exceed the 4,999-
  463.      character equation limit with your repeat values.
  464.  
  465.      COMMENTING YOUR EQUATIONS
  466.      SNR provides for writing comments in your tables. Comments can be
  467.      entered in a table as lines by themselves, or set off to the right of
  468.      an equation, as in this example:
  469.  
  470.           \ This is a comment line by itself.
  471.           \   A comment consists of a single backslash
  472.           \   followed by one or more spaces.
  473.  
  474.           \0d\0a=\0d\0a  \ this will ensure that existing CRLF pairs are
  475.                          \ left untouched
  476.           \0d=\0d\0a     \ this equation will convert an isolated CR
  477.                          \ into a CRLF
  478.           \0a=\0d\0a     \ this equation will convert an isolated LF
  479.                          \ into a CRLF
  480.           \\E
  481.  
  482.      When a comment follows an equation on the same line, any spaces that
  483.      occur before the comment are ignored; this is an exception to the all-
  484.      spaces-are-significant rule.
  485.  
  486.      If you're a programmer, or you've used a macro language of some kind,
  487.      you already know the value of program comments. If you're new to the
  488.      field of user programming, you should immediately get into the habit
  489.      of commenting your work. Believe me, you'll be glad you did, because a
  490.      time will come when you have to make a change to a table you created
  491.      months past, and you'll be left scratching your head over it if you
  492.      haven't commented the equations.
  493.  
  494.      EQUATION ORDERING
  495.      SNR will automatically sort equations by length when assembling a
  496.      table in memory. SNR does not process equations in sequential order
  497.      when it converts a file, so the order in which you enter your
  498.      equations is largely immaterial. The exceptions to this rule are when
  499.      using wild card patterns in your equations. This will be explained
  500.      further on.
  501.  
  502.  
  503.  
  504.                                       -8-                     SNR+ VER 5.03
  505.  
  506.  
  507.  
  508.      Equation processing is completed in a non-recursive fashion. That is,
  509.      once an equation has been matched and a replacement made, the replaced
  510.      data is not sent back for reconversion through another equation. It is
  511.      passed onto the output file once.
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.                                       -9-                     SNR+ VER 5.03
  568.  
  569.  
  570.  
  571.                                  CONTEXT FLAGS
  572.  
  573.      There are probably instances where you'd like to toggle between two
  574.      different replacement strings for the same search string. The context
  575.      flag allows you to do this. Some example uses would be:
  576.  
  577.      - to compress multiple spaces from a document
  578.      - to ignore any text between two codes
  579.      - to make one code alternate as two different codes
  580.      - to turn all-upper-case text into upper and lower
  581.  
  582.      There are undoubtedly many other uses.
  583.  
  584.      There are 16 context flags which can be used, and each context flag
  585.      has two states: on and off. The context flags are identified by the
  586.      numbers 0-9 and the letters a-f (for a total of 16 individual flags).
  587.  
  588.      When SNR begins execution, the context flags' states are all OFF. A
  589.      flag's state can be tested in a search, and its state can be set or
  590.      reset in a replacement. A context flag is represented in an equation
  591.      by an asterisk, followed by the number or letter of the flag, followed
  592.      by a one or zero (for ON or OFF).
  593.  
  594.      A context flag is the last item entered in a search or replacement
  595.      string. For example:
  596.  
  597.           ABC*00=abc*01
  598.           ABC*01=XYZ*00
  599.  
  600.      In the above two equations, if the string "ABC" is read from the input
  601.      file, and context flag 0 is OFF, then the string "abc" is written to
  602.      the output file, and context flag 0 is set ON. If, on the other hand,
  603.      the string "ABC" is read from the input file, and context flag 0 is
  604.      ON, then the string "XYZ" is written to the output file, and context
  605.      flag 0 is reset OFF. For example, if data from the input file looks
  606.      like this:
  607.  
  608.           ABCDEFG ABCDEFG ABCDEFG ABCDEFG
  609.  
  610.      ...our small example table would convert it to this:
  611.  
  612.           abcDEFG XYZDEFG abcDEFG XYZDEFG
  613.  
  614.      Context flags are global in scope; this means that each flag is
  615.      accessible by many different equations in one table, and any equation
  616.      can test or set the flags. But beware of unwanted side effects --
  617.      remember that only one equation at a time will control the state of a
  618.      flag, and its state may change between two equations that complement
  619.      each other, resulting in misconversion. For example:
  620.  
  621.           ABC*00=abc*01
  622.           ABC*01=XYZ*00
  623.           EFG*00=efg*01
  624.           EFG*01=ZYX*00
  625.  
  626.  
  627.  
  628.  
  629.  
  630.                                       -10-                    SNR+ VER 5.03
  631.  
  632.  
  633.  
  634.      The above equations are similar to the previous example, except that
  635.      we have defined two new equations that test and set a single context
  636.      flag. So, given this example input data:
  637.  
  638.           ABCDEFG ABCDEFG ABCDEFG ABCDEFG
  639.  
  640.      ...the result would convert to this:
  641.  
  642.           abcDZYX abcDZYX abcDZYX abcDZYX
  643.  
  644.      The context flag is being toggled by only two equations:
  645.  
  646.           ABC*00=abc*01  <--- this one
  647.           ABC*01=XYZ*00
  648.           EFG*00=efg*01
  649.           EFG*01=ZYX*00  <--- and this one
  650.  
  651.      If, on the other hand, the input data stream looked like this:
  652.  
  653.           ABCDEFG DEFGABC ABCDEFG DEFGABC
  654.  
  655.      ...the result would look like this:
  656.  
  657.           abcDZYX DefgXYZ abcDZYX DefgXYZ
  658.  
  659.      This conflict between two sets of equations grappling over the same
  660.      context flag can be alleviated by using a different flag number for
  661.      one of the sets:
  662.  
  663.           ABC*00=abc*01
  664.           ABC*01=XYZ*00
  665.           EFG*10=efg*11
  666.           EFG*11=ZYX*10
  667.  
  668.      Now the equations will have independent flags, and the data stream
  669.      will be processed using each equation separately. Now, this data
  670.      stream:
  671.  
  672.           ABCDEFG ABCDEFG ABCDEFG ABCDEFG
  673.  
  674.      ...will be converted to this:
  675.  
  676.           abcDefg XYZDZYX abcDefg XYZDZYX
  677.  
  678.      The thing to keep in mind if you are going to use a context flag is:
  679.      it is OFF when the program begins; you need to enter an equation to
  680.      set it ON; and then you need to have some equation that resets it OFF.
  681.  
  682.      See some of the sample tables for examples in the use of context
  683.      flags.
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.                                       -11-                    SNR+ VER 5.03
  694.  
  695.  
  696.  
  697.                            SPECIAL CONTEXT FLAG CODES
  698.  
  699.      Certain types of conversions involving context flags can be very
  700.      tedious to define. Take the case of a table whose task is to compress
  701.      two or more adjacent blank spaces into a single space. Using our
  702.      context flags, we would start out by setting a flag when we first
  703.      encounter a space:
  704.  
  705.           \20*00=\20*01
  706.  
  707.      This equation states that if a space is encountered and flag 0 is OFF,
  708.      it will be converted to one space and flag 0 ON. Next we define what
  709.      happens to a space when flag 0 is ON:
  710.  
  711.           \20*01=
  712.  
  713.      This equation states that a space and flag 0 ON, will be ignored. That
  714.      takes care of removing adjacent spaces, but there's something missing.
  715.      The way we have it set up now, EVERY subsequent space will be removed,
  716.      even between words, because we have not defined the case where flag 0
  717.      ever gets set OFF. Without something to set flag 0 OFF, only the
  718.      second equation will hold true.
  719.  
  720.      Since we have defined the case where adjacent spaces will be ignored,
  721.      we need to define the case where some character other than a space
  722.      will reset flag 0 so we can retain the single interword space
  723.      mentioned earlier.
  724.  
  725.      Here's where the tedium comes in. The complete solution is to make
  726.      every character EXCEPT a space set flag 0 OFF, like this:
  727.  
  728.           \00=\00*00
  729.           \01=\01*00
  730.           \02=\02*00
  731.           \03=\03*00
  732.           \04=\04*00
  733.           \05=\05*00
  734.               ...
  735.           \7c=\00*00
  736.           \7d=\00*00
  737.           \7e=\00*00
  738.               ...
  739.  
  740.      ...and so on. Basically, you'd need 255 similar equations to finish
  741.      the task.
  742.  
  743.      Specifically for these types of conversions, SNR provides two
  744.      specialty context flag codes: *ic and *ig.
  745.  
  746.      IGNORE CONSECUTIVE
  747.      The Ignore Consecutive (*ic) flag code is used on the right-hand side
  748.      of the conversion equation. Its purpose is to allow you to specify any
  749.      set of characters that will be ignored when encountered adjacently in
  750.      a data stream. A side benefit of this notation is that SNR will
  751.      automatically generate all of the other flag reset equations that are
  752.      needed to complete the conversion. This vastly reduces the "clutter"
  753.  
  754.  
  755.  
  756.                                       -12-                    SNR+ VER 5.03
  757.  
  758.  
  759.  
  760.      that would otherwise be present in your table. For instance, here is
  761.      our complete space compression table with the help of the *ic code:
  762.  
  763.           \20=\20*ic\20
  764.  
  765.      That's all there is to it. This equation reads: one space equals one
  766.      space, but ignore consecutive subsequent spaces.
  767.  
  768.      You may define more than one character after the *ic code. In fact,
  769.      you may define as many characters after the *ic code as you care to.
  770.      Each defined character will be ignored if they occur consecutively in
  771.      the data stream after matching the string on the left side of the
  772.      equation. Here's an example:
  773.  
  774.           .\20.\20.=<ldr>*ic\20.
  775.  
  776.      This equation will convert three periods separated by spaces into the
  777.      string <ldr>, and ignore any subsequent consecutive periods and
  778.      spaces. Thus, given the following input data:
  779.  
  780.           Price. . . . . . . . . . . . . . . $25.00
  781.  
  782.      ...the equation would convert it to this:
  783.  
  784.           Price<ldr>$25.00
  785.  
  786.      IGNORE GENERAL
  787.      The other specialty context flag code is the Ignore General (*ig)
  788.      code. This code appears on the right-hand side of an equation and its
  789.      purpose is to cause all characters occurring after the equation to be
  790.      ignored, until an Ignore Cancel (*ix) flag code is encountered.
  791.      Example:
  792.  
  793.           [=*ig
  794.           ]=*ix
  795.  
  796.      These two equations will cause anything falling between a left and
  797.      right square bracket to be ignored, including the brackets themselves.
  798.      Other characters falling outside of these delimiter characters will be
  799.      converted in normal fashion.
  800.  
  801.      The *ig/*ix notation is the quickest way to remove enclosed groups of
  802.      characters from a data stream.
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.                                       -13-                    SNR+ VER 5.03
  820.  
  821.  
  822.  
  823.                    START-OF-FILE AND END-OF-FILE CONVERSIONS
  824.  
  825.      SNR provides for special conversions to occur before and after normal
  826.      conversion of a data stream. These conversions can be useful in adding
  827.      specific headers or trailers to a file, or in removing portions of the
  828.      beginning and end of a file.
  829.  
  830.      START-OF-FILE CODE
  831.      To trigger an extra conversion at the start of the file, use the \s
  832.      start-of-file code. \s can be entered only as the first character on
  833.      the left-hand side of an equation. It may be used alone, or be
  834.      followed by other characters. Example:
  835.  
  836.           \s=<BEGIN>\0d\0a
  837.  
  838.      The above equation will output the string <BEGIN> as the first item in
  839.      a converted file.
  840.  
  841.           \s=*ic\20
  842.  
  843.      The above equation will ignore any group of consecutive spaces
  844.      occurring at the beginning of a file.
  845.  
  846.           \sNow is the time=
  847.  
  848.      The above equation will ignore the words "Now is the time" when they
  849.      occur at the beginning of a file.
  850.  
  851.      END-OF-FILE CODE
  852.      The \q end-of-file code works similarly to the start-of-file code.
  853.      When it is used in an equation, it will trigger a conversion at the
  854.      very end of a file. \q must always stand by itself on the left-hand
  855.      side of an equation; other characters can not follow it. Example:
  856.  
  857.           \q=[END OF JOB]\0d\0a
  858.  
  859.      The above equation will output the string [END OF JOB] at the very end
  860.      of a converted file.
  861.  
  862.      There is another use for the end-of-file code: to truncate a file when
  863.      a specific character is encountered in the data stream. (This
  864.      character may or may not occur at the true end of the file.) This is
  865.      very useful in cases where some programs add an end-of-file code to
  866.      any files they write, but you don't want them there. For instance, the
  867.      DOS COPY command adds a hex 1A to the end of a combined file when you
  868.      use the "+" operator to copy multiple files into one.
  869.  
  870.      To use this truncation feature, you first need to define a hex
  871.      character that will be recognized specifically as the end-of-file
  872.      character. At the beginning of your table, you must place the
  873.      following setup code:
  874.  
  875.           \\Qxx
  876.  
  877.      ...where "xx" is a two-digit hex code representing the character that
  878.      will trigger the end of file. For instance, the hex value 1A is
  879.      usually recognized as the DOS end-of-file character, so the setup code
  880.  
  881.  
  882.                                       -14-                    SNR+ VER 5.03
  883.  
  884.  
  885.  
  886.      for that case would be \\Q1A. The next step is to add the \q equation
  887.      to the table to actually process the end-of-file character:
  888.  
  889.           \q=
  890.  
  891.      This particular example will ignore the end-of-file character when it
  892.      is encountered in the data stream, but will terminate processing of
  893.      the file at that point, thus truncating the file.
  894.  
  895.      SPECIAL \s and \q INFORMATION
  896.      Because of the way SNR assembles and categorizes conversion equations,
  897.      any table that contains a \q or \s equation must be of a type that
  898.      contains at least one 1:n or m:n equation (this is an equation type
  899.      that has one or more characters on the left side of the equation, and
  900.      two or more characters on the right side of the equation). \s and \q
  901.      equations will not work in a table that contains only 1:0 or 1:1
  902.      equation types, because the 1:0 and 1:1 tables use a special high-
  903.      speed array translation routine that bypasses the standard equation
  904.      processing routines.
  905.  
  906.      A very simple way to coerce the table processor into categorizing a
  907.      1:1 table as an m:n type is to add the following equation to it:
  908.  
  909.           \80\80=\80\80
  910.  
  911.      This will have no adverse effect on the data stream, since it converts
  912.      two hex 80 characters as two hex 80 characters, but it will have the
  913.      desired effect in SNR's table type categorizing.
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.  
  932.  
  933.  
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  
  945.                                       -15-                    SNR+ VER 5.03
  946.  
  947.  
  948.  
  949.                                 WILD CARD CODES
  950.  
  951.      Now we get to the fun stuff. While SNR's string conversion
  952.      capabilities are quite powerful on their own, there are inevitably
  953.      times when it is necessary to perform conversions based on ambiguous
  954.      patterns of characters, rather than on literal characters themselves.
  955.      An example here would be if you had a comma-delimited ASCII file that
  956.      was created by a database program, and you noticed that none of the
  957.      phone numbers contained hyphens in them.
  958.  
  959.      It would be quite unfeasible to attempt to literally define all of the
  960.      possible phone numbers without hyphens, and convert them into phone
  961.      numbers with hyphens. You would end up with about 7 million equations
  962.      that went something like this:
  963.  
  964.           2220000=222-0000
  965.           2220001=222-0001
  966.           2220002=222-0002
  967.                ...
  968.           9989997=998-9997
  969.           9989998=998-9998
  970.  
  971.      ...hopefully, you get the idea. To help prevent such exercises in
  972.      futility, SNR provides a number of wild card codes than can be used in
  973.      place of literal characters in conversion equations. The wild card
  974.      codes allow you to search and replace on a set of characters rather
  975.      than on a specific character. For instance, one of the wild card codes
  976.      can be used to search for any of the numeric characters 0-9. Another
  977.      can be used to search for any of the alphabetic characters A-Z.
  978.  
  979.      There are 12 wild card codes in all:
  980.  
  981.           \p   any character
  982.           \n   numeric (0-9)
  983.           \x   full alphabetic (A-Z, a-z)
  984.           \u   upper case alphabetic (A-Z)
  985.           \y   lower case alphabetic (a-z)
  986.           \m   alphanumeric (A-Z, a-z, 0-9)
  987.           \t   punctuation
  988.           \g   non-whitespace
  989.           \o   whitespace (space, tab, return, line feed, vertical tab,
  990.                form feed)
  991.           \z   ASCII-only (c < ASCII 128)
  992.           \v   printable (c > ASCII 31)
  993.           \k   non-printable (c < ASCII 32)
  994.  
  995.      The least restrictive of these, \p, will match any character that is
  996.      encountered in the data stream. The most restrictive of these, \o,
  997.      will match only the set of a few "whitespace" characters. The other
  998.      wild card codes fall between these two extremes, and their associated
  999.      character sets should be fairly straightforward to understand.
  1000.  
  1001.      On the search side of an equation, a wild card code can be used as a
  1002.      straight substitute wherever a literal or hex character would be used.
  1003.      For instance, if you wanted to delete any pattern of three numbers
  1004.      contained in parentheses, you would enter the following equation:
  1005.  
  1006.  
  1007.  
  1008.                                       -16-                    SNR+ VER 5.03
  1009.  
  1010.  
  1011.  
  1012.           (\n\n\n)=
  1013.  
  1014.      This would delete such occurrences as (612), (000), (123) and so on.
  1015.  
  1016.      On the replacement side, however, wild card code usage requires some
  1017.      explanation -- here you can't simply use a wild card code in place of
  1018.      a literal character, as you can in the search string.
  1019.  
  1020.      SNR allows you to rearrange the order of wild card characters during
  1021.      conversion, so we need some method of numbering or otherwise
  1022.      identifying the position of each wild card code in the search string
  1023.      so it can be accessed in any order in the replacement string.
  1024.  
  1025.      This is done easily enough by convention: SNR sequentially numbers the
  1026.      characters in a search string. The leftmost search character is
  1027.      position 0, the next one is position 1, the next is position 2, and so
  1028.      on to the end of the string. The equation:
  1029.  
  1030.           (\n\n\n)=
  1031.  
  1032.      ...contains five characters: The left parenthesis is character 0, the
  1033.      wild card codes are characters 1, 2 and 3, and the right parenthesis
  1034.      is character 4. To use a wild card in a replacement string, then, we
  1035.      define the position of the character we wish to output, like this:
  1036.  
  1037.           (\n\n\n)=\p1\p2\p3
  1038.  
  1039.      The \p code, when used in a replacement string, is always followed by
  1040.      the position number of the character you wish to output. In the above
  1041.      example, when three numbers enclosed in parentheses are encountered in
  1042.      the data stream, the parentheses will be thrown out and only the three
  1043.      numbers will remain (in the same order in which they were defined in
  1044.      the search string). If we change the equation to read like this:
  1045.  
  1046.           (\n\n\n)=\p3\p1\p2
  1047.  
  1048.      ...the three numbers will be output in a different order.
  1049.  
  1050.      Let's return to the example we opened this section with -- that of
  1051.      replacing a series of phone numbers to add a hyphen between the third
  1052.      and fourth digits. Now that we have wild card codes available as a
  1053.      conversion tool, the task becomes much simpler:
  1054.  
  1055.           \n\n\n\n\n\n\n=\p0\p1\p2-\p3\p4\p5\p6
  1056.  
  1057.      Look at the equation: seven numbers on the search side will be
  1058.      replaced by the first three numbers, followed by a hyphen, followed by
  1059.      the last four numbers. If the data stream contained 4315805, the
  1060.      equation would convert it to 431-5805. We could even handle area
  1061.      codes:
  1062.  
  1063.           \n\n\n\n\n\n\n\n\n\n=(\p0\p1\p2) \p3\p4\p5-\p6\p7\p8\p9
  1064.  
  1065.      The equation as written defines 10 numbers on the search side to be
  1066.      replaced by: a left parenthesis, the first three numbers, a right
  1067.      parenthesis and a space, the next three numbers, a hyphen, and the
  1068.  
  1069.  
  1070.  
  1071.                                       -17-                    SNR+ VER 5.03
  1072.  
  1073.  
  1074.  
  1075.      last four numbers. If the data stream contained 6124315805, the
  1076.      equation would convert it to (612) 431-5805.
  1077.  
  1078.      As an aid to equation readability, repeated numbers of wild card codes
  1079.      can use the repeating-character notation described in the first
  1080.      section:
  1081.  
  1082.           *(10)\n=(\p0\p1\p2) \p3\p4\p5-\p6\p7\p8\p9
  1083.  
  1084.      This eliminates the need for you to specifically count how many \n
  1085.      codes you've entered in a search string. The above equation has
  1086.      exactly the same meaning as the previous equation. In a replacement
  1087.      string, you can also use the repeating-character notation, so long as
  1088.      you identify which position is being initially output:
  1089.  
  1090.           *(10)\n=(*(3)\p0) *(3)\p3-*(4)\p6
  1091.  
  1092.      Look at the equation; it defines 10 numeric characters to be replaced
  1093.      by: a left parenthesis, three numeric characters starting at position
  1094.      0, a right parenthsis, a space, three numeric characters starting at
  1095.      position 3, a hyphen, and four numeric characters starting at position
  1096.      6. This is exactly the same equation as the one defined three
  1097.      paragraphs ago, but it is shorter and perhaps easier to read.
  1098.  
  1099.      Which notation you ultimately use -- long or short -- is purely a
  1100.      matter of personal taste and appropriateness for the equation at hand.
  1101.      Some equations will be more readable using the "long" notation, while
  1102.      others will be a natural fit for the "short" version. There is no need
  1103.      to dogmatically rely upon one or the other.
  1104.  
  1105.      MIXING WILD CARD CODES
  1106.      Wild card codes can be intermixed in an equation. For instance, the
  1107.      following equation will convert a comma, a space, two upper case
  1108.      letters, and five numbers into: a comma, a space, two upper case
  1109.      letters, two spaces, and five numbers:
  1110.  
  1111.           , \u\u\n\n\n\n\n=, \p2\p3  *(5)\p4
  1112.  
  1113.      So if this string of characters was encountered in the data stream:
  1114.  
  1115.           , MN55044
  1116.  
  1117.      ...the equation would convert it to:
  1118.  
  1119.           , MN  55044
  1120.  
  1121.      CONVERTING SHIFT CASE
  1122.      Aside from \p, two other wild card codes can be used in a replacement
  1123.      string. Their purpose is to alter the shift case of an alphabetic
  1124.      character. The codes are \u and \y, for upper and lower conversion. As
  1125.      an example, we can make the sample equation dealing with the state and
  1126.      zip code used earlier a lot more universal with these new replacement
  1127.      wild cards:
  1128.  
  1129.           , \x\x\n\n\n\n\n=, \u2\u3  *(5)\p4
  1130.  
  1131.  
  1132.  
  1133.  
  1134.                                       -18-                    SNR+ VER 5.03
  1135.  
  1136.  
  1137.  
  1138.      This new equation will convert a comma, a space, two alphabetic
  1139.      characters of undetermined case, and five numbers into: a comma, a
  1140.      space, two upper case characters, two spaces, and five numbers.
  1141.  
  1142.      So if the following items were encountered in the data stream:
  1143.  
  1144.           , MN55044
  1145.           , Ny10022
  1146.           , il60301
  1147.           , nJ07680
  1148.  
  1149.      ...the equation would convert them to:
  1150.  
  1151.           , MN  55044
  1152.           , NY  10022
  1153.           , IL  60301
  1154.           , NJ  07680
  1155.  
  1156.      Here is set of equations that will convert a text file that is
  1157.      entirely in upper case into one that consists of upper and lower case,
  1158.      in sentence style:
  1159.  
  1160.           \u*00=\p0*01
  1161.           \u*01=\y0
  1162.           .=.*00
  1163.  
  1164.      In this equation, when an upper case letter is encountered in the data
  1165.      stream, and flag 0 is OFF, it is output as-is and flag 0 is set ON. If
  1166.      an upper case letter is encountered and flag 0 is ON, it is converted
  1167.      to a lower case letter. If a period is encountered, it is output as-is
  1168.      and flag 0 is set OFF, so the next upper case letter will be output
  1169.      as-is. Any other characters in the file will be passed through as-is.
  1170.  
  1171.      From this example data stream:
  1172.  
  1173.           NOW IS THE TIME. FOR ALL GOOD MEN. TO COME TO THE AID.
  1174.  
  1175.      ...the equation would produce:
  1176.  
  1177.           Now is the time. For all good men. To come to the aid.
  1178.  
  1179.      How would you alter the above small table to convert a file from all
  1180.      upper case to initial upper case, where the first letter of each word
  1181.      is capitalized? Stated another way, what character appears before each
  1182.      word that could be used to control the flag? Here's the answer:
  1183.  
  1184.           \u*00=\p0*01
  1185.           \u*01=\y0
  1186.           .=.*00
  1187.           \20=\20*00
  1188.  
  1189.      Just by adding the last line to the equation, a space will set flag 0
  1190.      to OFF, forcing the next character to be output as upper case.
  1191.  
  1192.      Now the previous sample data stream will be converted to:
  1193.  
  1194.           Now Is The Time. For All Good Men. To Come To The Aid.
  1195.  
  1196.  
  1197.                                       -19-                    SNR+ VER 5.03
  1198.  
  1199.  
  1200.  
  1201.  
  1202.      WILD CARDS AND \s
  1203.      You can use wild cards in conjunction with the \s start-of-file code
  1204.      to remove a number of characters from the beginning of a file:
  1205.  
  1206.           \s*(256)\p=
  1207.  
  1208.      The above equation will remove the first 256 characters (of any type)
  1209.      from a file.
  1210.  
  1211.      BEWARE OF SIDE EFFECTS
  1212.      Wild card codes are powerful tools. They can also be powerfully
  1213.      troublesome if not used with care. Keep in mind that these wild card
  1214.      codes have a hierarchy of pattern-matching: they range from highly
  1215.      inclusive to highly restrictive. If you have two or more wild card
  1216.      equations in your table, be keen to the possibility that one of the
  1217.      equations might end up taking precedence over another, leading to
  1218.      unintended conversions.
  1219.  
  1220.      SNR bases its pattern-matching tests on the total length of search
  1221.      equations. That is, for any string in the data stream that could
  1222.      potentially match two or more table equations, the equation that is
  1223.      longest will be tried first. The next longest one will be next, and so
  1224.      on down the line until no further equations meet the pattern in the
  1225.      data stream item.
  1226.  
  1227.      So, for any two equations that begin with the same character, the
  1228.      longer one will be tested before the shorter one. If the longer one
  1229.      happens to match the data stream pattern, it is replaced immediately,
  1230.      and none of the other equations will be tested.
  1231.  
  1232.      If two wild card equations have the same search string length but
  1233.      begin with a different wild card code, the equation with the wild card
  1234.      code that is more restrictive will be tested first. That is, if an
  1235.      equation beginning with \x and one beginning with \v are both the same
  1236.      length, the one beginning with \x will be tested against the data
  1237.      stream first, because the set of alphabetic characters is more
  1238.      exclusive than the set of all printable characters.
  1239.  
  1240.      Design your wild card search strings carefully to take this behavior
  1241.      into consideration, and your conversions will be more successful.
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.                                       -20-                    SNR+ VER 5.03
  1261.  
  1262.  
  1263.  
  1264.                           VARIABLE-LENGTH CONVERSIONS
  1265.  
  1266.      Up to now, the conversions that we have been discussing have dealt
  1267.      with fixed-length patterns of characters: some number of characters in
  1268.      a search string gets converted to some other number of characters in a
  1269.      replacement string, and we have been able to specifically count the
  1270.      number of characters on either side of the equation.
  1271.  
  1272.      Now we are going to explore the method SNR has of defining repeating
  1273.      characters or wild card codes whose actual number is unknown. These
  1274.      types of equations are called "variable-length" conversions.
  1275.  
  1276.      Variable-length conversions are used when you want to search on some
  1277.      identifiable set of characters -- maybe a line of text, maybe a
  1278.      phrase, maybe a command parameter -- but you don't know HOW MANY
  1279.      characters will be involved in the actual pattern.
  1280.  
  1281.      For instance, a line of text might contain one word, or it might
  1282.      contain fifty words. An imbedded text command might contain one
  1283.      parameter, or it might contain twelve parameters. A comma-delimited
  1284.      database field might contain ten characters, or it might contain
  1285.      twenty-five characters.
  1286.  
  1287.      The one thing that these types of text patterns -- a line, a
  1288.      parameter, a field -- have in common is that we wish to treat each of
  1289.      them as a unit, even though we don't know how many characters they
  1290.      will contain.
  1291.  
  1292.      Using variable-length conversions, you can define these higher-level
  1293.      units of data and translate them, throw them away, or rearrange them
  1294.      as needed.
  1295.  
  1296.      SEARCH STRING FUNDAMENTALS
  1297.      A variable-length string is declared to be a set of a specific type of
  1298.      character (literal or wild card) that matches from zero to a stated
  1299.      maximum length of similar characters in the data stream.
  1300.  
  1301.      Since variable-length search strings are basically unspecified lengths
  1302.      of similar characters, we can draw upon the notation that we
  1303.      prescribed earlier for the repeating-character strings:
  1304.  
  1305.           *(40)\20
  1306.  
  1307.      The above portion of a search string should be familiar to you as the
  1308.      definition for 40 spaces. To turn this into a variable-length
  1309.      definition, we add the \^ variable-length code:
  1310.  
  1311.           \^*(40)\20
  1312.  
  1313.      This search string fragment now defines "up to" 40 spaces. Likewise,
  1314.      the following fragment defining a string of 25 alphabetic characters:
  1315.  
  1316.           *(25)\x
  1317.  
  1318.      ...can be redescribed in variable-length terms like this:
  1319.  
  1320.           \^*(25)\x
  1321.  
  1322.  
  1323.                                       -21-                    SNR+ VER 5.03
  1324.  
  1325.  
  1326.  
  1327.  
  1328.      This search fragment now defines a string of "up to" 25 alphabetic
  1329.      characters.
  1330.  
  1331.      It is important to adhere to the following rules when you use
  1332.      variable-length search strings:
  1333.  
  1334.           - An equation cannot begin with a variable-length search string.
  1335.           - Each variable-length search string must be followed by a fixed-
  1336.             length terminator string.
  1337.  
  1338.      These restrictions are not quite so arbitrary as they may seem. As for
  1339.      the first rule, each equation must have some character or set of
  1340.      characters of fixed length that can begin the search pattern. The
  1341.      variable-length string can come right after this. As for the second
  1342.      rule, there must be something to tell SNR when the end of a variable-
  1343.      length string has been met; some specific character or set of
  1344.      characters must be defined that can act as a terminator to the
  1345.      variable-length string. The second rule also implies that the search
  1346.      side of an equation cannot end with a variable-length string.
  1347.  
  1348.      So here is a complete example of a valid variable-length search
  1349.      string:
  1350.  
  1351.           \v\^*(80)\v\0d\0a=
  1352.  
  1353.      Look at the equation. It defines: a printable character followed by up
  1354.      to 80 more printable characters terminated by a carriage return/line
  1355.      feed, to be thrown away. The effect of this equation will be to throw
  1356.      away full lines that are less than 82 characters long, or to throw
  1357.      away the last 82 characters of a longer line.
  1358.  
  1359.      Multiple variable-length strings can appear in an equation:
  1360.  
  1361.           "\^*(30)\v","\^*(30)\v","\^*(30)\v"\0d\0a=
  1362.  
  1363.      The above equation will search for: a quote followed by up to 30
  1364.      printable characters followed by a quote-comma-quote terminator
  1365.      followed by up to 30 more printable characters followed by another
  1366.      quote-comma-quote terminator followed by up to 30 more printable
  1367.      characters terminated by a quote and carriage return/line feed, and
  1368.      throw it all away. You may recognize this particular pattern as being
  1369.      characteristic of the comma-delimited ASCII file that many database
  1370.      and mail-merge programs support.
  1371.  
  1372.      The two examples we used above employed literal characters as
  1373.      terminator strings. It is equally valid to use wild card codes as
  1374.      terminator strings:
  1375.  
  1376.           \n\^*(20)\n\t=
  1377.  
  1378.      The above equation defines a number followed by up to 20 more numbers
  1379.      followed by a punctuation character to be thrown away.
  1380.  
  1381.      When you use wild card codes as a terminator to a variable-length
  1382.      string which itself uses wild cards, remember the earlier admonition
  1383.      concerning the hierarchy of wild card pattern matching. It applies
  1384.  
  1385.  
  1386.                                       -22-                    SNR+ VER 5.03
  1387.  
  1388.  
  1389.  
  1390.      equally here. Specifically, a wild card terminator must be more
  1391.      restrictive in type than the variable-length wild card string it is
  1392.      terminating.
  1393.  
  1394.      For instance, the following variable-length string is invalid:
  1395.  
  1396.           \n\^*(10)\n\p=
  1397.  
  1398.      The \p code used as the terminator has a higher inclusion value than
  1399.      the \n code. The result will be that this equation will generate
  1400.      incorrect output, if indeed it outputs anything at all.
  1401.  
  1402.      REPLACEMENT STRING FUNDAMENTALS
  1403.      The prior discussion concerned itself exclusively with the procedures
  1404.      for defining the search side of an equation. Now we will turn our
  1405.      attention to defining the replacement side of a variable-length
  1406.      equation.
  1407.  
  1408.      Since we don't know the actual number of characters that a variable-
  1409.      length string will pick up, it is not possible to use the \p notation
  1410.      to identify precise character positions for output. Instead, we
  1411.      identify groups of variable-length strings by the positions of the
  1412.      group: the first variable-length string on the search side is number
  1413.      one, the next such string in the equation is number two, and so on.
  1414.      (This is in contrast to the \p code, which begins at zero.)
  1415.  
  1416.      Up to 40 variable-length strings may be entered in a single equation.
  1417.  
  1418.      The variable-length replacement strings are defined as \^1, \^2, \^3
  1419.      and so on. Let's take an example based on the comma-delimited ASCII
  1420.      file, used earlier:
  1421.  
  1422.           "\^*(30)\v","\^*(30)\v","\^*(30)\v"\0d\0a=\^1\09\^2\09\^3\0d\0a
  1423.  
  1424.      While the search side of the equation remains the same as before, we
  1425.      have now introduced the replacement side. The replacement will be the
  1426.      first variable-length string followed by a tab code (the hex 09)
  1427.      followed by the second variable-length string followed by a tab code
  1428.      followed by the third variable-length string followed by a carriage
  1429.      return/line feed. The effect of this equation will be to convert a
  1430.      comma-quote delimited file into a tab-delimited file. (Digression: for
  1431.      purposes of illustration this example is fine, but is there a better
  1432.      way to accomplish the same result? The answer appears in a later
  1433.      section.)
  1434.  
  1435.      You may have observed by insight that it is possible to rearrange the
  1436.      strings by changing the order in which they appear on the replacement
  1437.      side of the equation. The procedure is straightforward and obvious, so
  1438.      I won't bother with an illustration.
  1439.  
  1440.      How do you output a wild card character that has been defined as a
  1441.      terminator? Since you can't pick the character out of the data stream
  1442.      by exact position, SNR provides a notation that describes a terminator
  1443.      string. Since each variable-length string in an equation is numbered
  1444.      from 1 to 40, and by definition each variable-length string must be
  1445.      followed by a terminator string, it makes sense that the terminator
  1446.      strings are also numbered from 1 to 40.
  1447.  
  1448.  
  1449.                                       -23-                    SNR+ VER 5.03
  1450.  
  1451.  
  1452.  
  1453.  
  1454.      The replacement notation for terminator strings is \^:1, \^:2, \^:3
  1455.      and so on (the colon being the only difference between them and the
  1456.      variable-length string identifier).
  1457.  
  1458.      Now having some way of differentiating between variable-length strings
  1459.      and terminators, we can convert equations such as the following:
  1460.  
  1461.           \u\^*(15)\y\u\^*(15)\y\t=\p0\^1\^:1\20\^2\^:2
  1462.  
  1463.      This admittedly contrived example serves to illustrate the placement
  1464.      and usage of the various codes. The search side defines an upper case
  1465.      character followed by up to 15 lower case characters terminated by an
  1466.      upper case character followed by up to 15 more lower case characters
  1467.      terminated by a punctuation character. The replacement side outputs
  1468.      the first character of the string (the first \u on the search side)
  1469.      followed by the first variable-length string followed by the first
  1470.      terminator followed by a space followed by the second variable-length
  1471.      string followed by the second terminator.
  1472.  
  1473.      For a concrete example, assume that this string occurs in the data
  1474.      stream:
  1475.  
  1476.           SuperDuper! UnquestionablyAwesome.
  1477.  
  1478.      Our example equation will convert it to this:
  1479.  
  1480.           Super Duper! Unquestionably Awesome.
  1481.  
  1482.      Let's try switching the order of a few elements in the equation:
  1483.  
  1484.           \u\^*(15)\y\u\^*(15)\y\t=\^:1\^2\20\p0\^1\^:2
  1485.  
  1486.      The search side remains the same; the replacement side has changed.
  1487.      Study it and see if you can follow the meaning. Perhaps this will
  1488.      help: given the same example data stream as above, the altered
  1489.      equation will produce this output:
  1490.  
  1491.           Duper Super! Awesome Unquestionably.
  1492.  
  1493.      PADDING VARIABLE-LENGTH STRINGS
  1494.      A specialized use of variable-length replacement strings allows the
  1495.      strings to be padded out to their maximum width. Normally, of course,
  1496.      the strings are output to their "natural" width -- however many
  1497.      characters are contained in the data stream are what gets output
  1498.      during replacement.
  1499.  
  1500.      Padding the strings adds blank spaces to the left or right of the text
  1501.      proper, and has the effect of aligning the text within a field that is
  1502.      as wide as the maximum width specified in the variable-length search
  1503.      string.
  1504.  
  1505.      To invoke variable-length padding, the alignment codes R and L are
  1506.      inserted before the variable-length string number in a replacement
  1507.      string. For instance, \^L1 will left-align the first variable-length
  1508.      string; \^R3 would right-align the third variable-length string.
  1509.      Here's how the codes are used in an equation:
  1510.  
  1511.  
  1512.                                       -24-                    SNR+ VER 5.03
  1513.  
  1514.  
  1515.  
  1516.  
  1517.           "\^*(30)\v","\^*(30)\v","\^*(30)\v"\0d\0a=\^L1\^L2\^R3\0d\0a
  1518.  
  1519.      Taking our well-worn comma-delimited example yet again, pay particular
  1520.      attention to the replacement side. Those codes specify that the first
  1521.      variable-length string will be output left-aligned to a width of 30
  1522.      characters, the second variable-length field will be output left-
  1523.      aligned to a width of 30 characters, and the third variable-length
  1524.      field will be output right-aligned to a width of 30 characters
  1525.      followed by a carriage return/line feed. What we have done in this
  1526.      example is converted a file containing comma-delimited fields into a
  1527.      file containing fixed-length fields.
  1528.  
  1529.      The widths of the fields can be changed simply by changing the width
  1530.      values in the search strings:
  1531.  
  1532.           "\^*(35)\v","\^*(25)\v","\^*(40)\v"\0d\0a=\^L1\^L2\^R3\0d\0a
  1533.  
  1534.      In this case, the replacement side of the equation is the same as
  1535.      before, but the search side now contains different widths for each of
  1536.      the fields. This will affect the appearance of the output when the
  1537.      text is padded; it will not affect the appearance of the text if the
  1538.      alignment codes are removed.
  1539.  
  1540.      PAD CHARACTER
  1541.      By default, variable-length strings are padded with spaces when the R
  1542.      or L alignment codes are specified. You can select a different padding
  1543.      character by placing the setup code \\Axx at the beginning of your
  1544.      table, where "xx" is a hex value representing the character you wish
  1545.      to use as the padding character. Only one padding character may be
  1546.      defined per table, and once selected, it can not be changed.
  1547.  
  1548.      As an example, you could pad your variable-length text strings with
  1549.      periods by using the setup code:
  1550.  
  1551.           \\A2E
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.                                       -25-                    SNR+ VER 5.03
  1576.  
  1577.  
  1578.  
  1579.                                  HINTS AND TIPS
  1580.  
  1581.      The conversion capabilities of SNR are very sophisticated. Some of
  1582.      them are subtle, and require some study and experimentation to master.
  1583.      Here is a list of a few pointers that might help you avoid the
  1584.      pitfalls of inexperience.
  1585.  
  1586.      1.   Lots of smaller tables are better than one large table.
  1587.  
  1588.           It is sometimes tempting to create a huge, do-it-all conversion
  1589.           table that takes care of your conversion task all at once. Let me
  1590.           tell you from experience that it is much better to break down
  1591.           your conversion into a series of smaller tables that are run one
  1592.           after the other.
  1593.                One reason behind this is that it is much simpler to
  1594.           pinpoint problems when you take your conversion a little bit at a
  1595.           time, and you won't waste your energy poking around a large table
  1596.           feebly trying to discover why your text isn't converting the way
  1597.           you thought it should.
  1598.                Remember that SNR allows you to run up to 20 tables at one
  1599.           time on the command line anyway, giving you the same benefit as
  1600.           having one large table.
  1601.                Another reason to break your task into smaller pieces is
  1602.           that some of the more advanced conversion models -- such as
  1603.           variable-length strings -- may have unwanted side effects on
  1604.           other equations or vice versa. It is safer to isolate the complex
  1605.           portions of a conversion task into their own tables to insure
  1606.           that harmful side effects are not introduced.
  1607.  
  1608.      2.   Use literal characters over wild cards wherever possible.
  1609.  
  1610.           Wild cards are very powerful, but they require much more time to
  1611.           process than literal characters. Whenever you can, it is
  1612.           preferable to define conversion equations using literal
  1613.           characters instead of wild cards.
  1614.                If your conversion task can be represented by a few well-
  1615.           defined data patterns, it's a good candidate for literal
  1616.           equations. If, on the other hand, you have a particular need to
  1617.           search a wide range of data patterns, then the wild card equation
  1618.           is your best choice.
  1619.                Remember the question I posed back in the variable-length
  1620.           section? I asked if there was a better way than using variable-
  1621.           length strings to convert a comma-delimited text file into a tab-
  1622.           delimited text file. The answer is yes. If you think about it a
  1623.           little bit, there is no real need to do any conversion of the
  1624.           data within the delimiters at all. Only the delimiters themselves
  1625.           need to be converted. So rather than chewing up a lot of CPU
  1626.           cycles scanning the data stream for variable-length text, the
  1627.           following two equations will perform the conversion much faster:
  1628.  
  1629.                "=
  1630.                ","=\09
  1631.  
  1632.           An added benefit to using this table over the other one is that
  1633.           this version does not need to be modified when the number of
  1634.           fields changes, whereas the other one does. I guess this is one
  1635.           of those situations where Less Is More.
  1636.  
  1637.  
  1638.                                       -26-                    SNR+ VER 5.03
  1639.  
  1640.  
  1641.  
  1642.  
  1643.      3.   Use context flags rather than variable-length patterns when you
  1644.           are seeking to compress the data stream.
  1645.  
  1646.           This is another issue related to efficiency. Variable-length
  1647.           conversion strings provide a means of reading an unspecified
  1648.           number of consecutive characters and eliminating them, in effect
  1649.           compressing the data stream. But equations using context flags
  1650.           such as *ic or *ig provide a much faster conversion than
  1651.           variable-length equations.
  1652.  
  1653.      4.   Debug your tables an equation at a time.
  1654.  
  1655.           Debugging is a cross between an art and a science; it requires
  1656.           both discipline and inspiration to do it well. The first step in
  1657.           effective debugging is to find the trouble spot and focus your
  1658.           attention on it.
  1659.                The easiest way to do this in SNR is to place a comment code
  1660.           (backslash followed by a space) in front of every equation in
  1661.           your table, and enable each equation one at a time. Test a sample
  1662.           of your data file for each new equation that you enable.
  1663.           Eventually, you will hit upon the one equation that is fouling
  1664.           things up, and you will be able to alter it or isolate it by
  1665.           moving it to another table, where it can be dissected and
  1666.           analyzed apart from other equations.
  1667.                Once the trouble equation has been found, look at it
  1668.           carefully. Consider these questions:
  1669.                - Are you sure it is defined according to the rules set
  1670.                  forth in this document?
  1671.                - Does each element of the equation logically match a likely
  1672.                  pattern in the data stream?
  1673.                - Are your wild card definitions too vague to match a
  1674.                  specific pattern in the data stream?
  1675.                - Are there any possible conflicts between elements of the
  1676.                  equation that would render it invalid?
  1677.                - Can the equation be restated equivalently in different
  1678.                  terms, that is, using a different conversion model (for
  1679.                  example, transforming wild cards into literals)?
  1680.                - Is what you are trying to do reasonable or even possible
  1681.                  in the SNR conversion paradigm?
  1682.                - Have you done something like this before and made it work?
  1683.                - Is there a similar equation shown in the sample tables?
  1684.                - Could there be a bug in SNR?
  1685.                Seeking the answers to these questions will help guide your
  1686.           troubleshooting steps in a logical, scientific manner.
  1687.  
  1688.      5.   Use lots of comments.
  1689.  
  1690.           This point was brought up in the first section of the manual, but
  1691.           it bears repeating. 'Nuff said.
  1692.  
  1693.      6.   Peruse the provided example tables.
  1694.  
  1695.           The range of possible uses of SNR, and the examples to support
  1696.           them, are beyond the scope of this manual. Many of the more
  1697.           complex and subtle uses of conversion strings can only be
  1698.  
  1699.  
  1700.  
  1701.                                       -27-                    SNR+ VER 5.03
  1702.  
  1703.  
  1704.  
  1705.           appreciated by experimentation or by looking through the example
  1706.           tables provided in the archive file.
  1707.                The tables may help provide you with hints on syntax and
  1708.           usage that this manual was unable to. If you register the
  1709.           program, you will be entitled to telephone or on-line support
  1710.           (toll at your expense) and I will be happy to help you solve your
  1711.           conversion problems.
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.  
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748.  
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.                                       -28-                    SNR+ VER 5.03
  1765.  
  1766.  
  1767.  
  1768.                                  MISCELLANEOUS
  1769.  
  1770.      BIT STRIPPING
  1771.      In prior versions of SNR, the default action was to map all incoming
  1772.      characters to 7-bit ASCII before running them through the equations.
  1773.      In version 5, this has been changed: no "bit-stripping" is performed
  1774.      by default. If you wish to have your table map incoming characters to
  1775.      a 7-bit ASCII set, you must enter the \\L7 setup code at the beginning
  1776.      of your table.
  1777.  
  1778.      NOTES
  1779.      The program will run on any IBM-compatible computer using DOS 3.0 or
  1780.      higher, with a minimum of 512K RAM.
  1781.  
  1782.      SNR was written in Borland C++ 3.1.
  1783.  
  1784.      DISCLAIMER
  1785.      This program is distributed as shareware. Use it, copy it, upload it,
  1786.      give it to your friends. Please distribute only the complete program
  1787.      in archived form, including all document and sample files. No
  1788.      warranties, either expressed or implied, are given by the author or
  1789.      distributor of the program, and the user accepts all risk of damage
  1790.      arising out of the application and use of the program.
  1791.  
  1792.      REGISTRATION
  1793.      If you like SNR, please register your copy for $50. At that price,
  1794.      it's one of the bargains of the text processing world, and I'll bet
  1795.      you recoup that investment dozens, maybe hundreds, of times over in
  1796.      the work it will save you.
  1797.  
  1798.      Registered users will receive a version of the program that does not
  1799.      have the compliance delay screen. Also included FREE with the
  1800.      registered version is TurboEdit, a DOS text editor that provides a
  1801.      multiple-window, mouse-supported editing environment with a built-in
  1802.      ASCII table and calculator (very useful for editing your conversion
  1803.      tables).
  1804.  
  1805.      Please fill out and return with your payment the form in the file
  1806.      ORDER.FRM.
  1807.  
  1808.      Registered users are guaranteed a response to technical support
  1809.      questions by phone, mail, or CompuServe. Unregistered users will
  1810.      receive responses on a time-available basis, but I can't guarantee
  1811.      that I will respond to those requests.
  1812.  
  1813.  
  1814.  
  1815.  
  1816.  
  1817.  
  1818.  
  1819.  
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826.  
  1827.                                       -29-                    SNR+ VER 5.03
  1828.